package cn.edu.scau.cmi.dengshixin.abstractFactory;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;

import cn.edu.scau.cmi.dengshixin.brand.*;
import cn.edu.scau.cmi.dengshixin.factoryProduct.Meat;

public class Controller {

    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private Label advertisementLabel;

    @FXML
    private TextField companyInputField;

    @FXML
    private Label brandLabel;

    @FXML
    private Button advertiseButton;

    @FXML
    private Label cookLabel;

    @FXML
    private Button cookButton;

    @FXML
    private TextField meatInputField;
    
    Factory companyChosen(String company) {
    	switch(company) {
		case "Wens":
			brandLabel.setText(Wens.brand);
			advertisementLabel.setText(Wens.advertisement());
			return new WensMeatFactory();
		case "Tianbang":
			brandLabel.setText(Tianbang.brand);
			advertisementLabel.setText(Tianbang.advertisement());
			return new TianbangMeatFactory();
		case "Aonong":
			brandLabel.setText(Aonong.brand);
			advertisementLabel.setText(Aonong.advertisement());
			return new AonongMeatFactory();
		}
    	return null;
    }

    @FXML
    void cook(ActionEvent event) {
    	String meatName = meatInputField.getText();
    	String company = companyInputField.getText();
    	meatInputField.clear();
    	companyInputField.clear();
    	if(meatName.equals("") || company.equals("")) return;
    	
    	Factory factory = companyChosen(company);
    	if(factory != null) {
    		Meat meat = factory.produce(meatName);
    		cookLabel.setText(meat.cook());
    	}
    }

    @FXML
    void advertise(ActionEvent event) {
    	String company = companyInputField.getText();
    	if(company.equals("")) return;
    	
    	companyChosen(company);
    }

    @FXML
    void initialize() {
        assert advertisementLabel != null : "fx:id=\"advertisementLabel\" was not injected: check your FXML file 'AbstractFactoryFX.fxml'.";
        assert companyInputField != null : "fx:id=\"companyInputField\" was not injected: check your FXML file 'AbstractFactoryFX.fxml'.";
        assert brandLabel != null : "fx:id=\"brandLabel\" was not injected: check your FXML file 'AbstractFactoryFX.fxml'.";
        assert advertiseButton != null : "fx:id=\"advertiseButton\" was not injected: check your FXML file 'AbstractFactoryFX.fxml'.";
        assert cookLabel != null : "fx:id=\"cookLabel\" was not injected: check your FXML file 'AbstractFactoryFX.fxml'.";
        assert cookButton != null : "fx:id=\"cookButton\" was not injected: check your FXML file 'AbstractFactoryFX.fxml'.";
        assert meatInputField != null : "fx:id=\"meatInputField\" was not injected: check your FXML file 'AbstractFactoryFX.fxml'.";

    }
}
